package com.online.teaching.module.teacher.teaches.controller;

import com.github.pagehelper.PageInfo;
import com.online.teaching.module.teacher.homework.domain.dto.HomeWorkAddDTO;
import com.online.teaching.module.teacher.teaches.domain.vo.GetStudentListVO;
import com.online.teaching.module.teacher.teaches.domain.vo.GetTeachesListVO;
import com.online.teaching.module.teacher.teaches.service.TeacherTeachesService;
import com.online.teaching.utils.Result;
import com.online.teaching.utils.StatusCode;
import com.online.teaching.utils.TokenDecode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName : StudentBlogController  //类名
 * @Description :   //描述
 * @Author : YG  //作者
 * @Date: 2020-11-04 13:20  //时间
 */
@Api(tags ="老师操作课程模块")
@RestController
public class TeacherTeachesController {

    @Autowired
    private TeacherTeachesService teacherTeachesService;

    @Autowired
    private TokenDecode tokenDecode;

    @ApiOperation(value = "老师查询授课列表", notes = "老师查询授课列表")
    @GetMapping("teacher/teaches/getTeachesList")
    public Result<List<GetTeachesListVO>> getTeachesList()
    {
        Integer id = Integer.valueOf(tokenDecode.getUserInfo().get("id"));
        List<GetTeachesListVO> teachesList = teacherTeachesService.getTeachesList(id);
        return new Result(true, StatusCode.OK,"查询成功",teachesList);
    }

    @ApiOperation(value = "老师查询某一门课学生列表", notes = "老师查询某一门课学生列表")
    @GetMapping("teacher/teaches/getStudentList")
    public Result<PageInfo<GetStudentListVO>> getTeachesStudentList(@ApiParam("teachesId") @RequestParam("teachesId")Integer teachesId,
                                        @ApiParam("第几页")@RequestParam("page") Integer page,
                                        @ApiParam("数量")@RequestParam("size") Integer size)
    {
        PageInfo<GetStudentListVO> teachesStudentList = teacherTeachesService.getTeachesStudentList(teachesId, page, size);
        return new Result(true,StatusCode.OK,"查询成功",teachesStudentList);
    }

    @ApiOperation(value = "老师编辑课程介绍", notes = "老师编辑课程介绍")
    @PostMapping("teacher/teaches/editIntroduction")
    public Result editIntroduction(@ApiParam("课程介绍") @RequestParam("introduction")String introduction,
                                   @ApiParam("teachesId") @RequestParam("teachesId")Integer teachesId)
    {
        int i = teacherTeachesService.editIntroduction(introduction, teachesId);
        return i==1?new Result(true, StatusCode.OK,"课程介绍编辑成功"):new Result(true,StatusCode.ERROR,"课程介绍编辑失败");
    }
}
